apiready = function() {
    seajs.use(['../../V', "../../api", "../../jquery", "../../app", "../../service"], function(V, $api, $, $app, service) {
      $app.ready();
        var vm = {
            el: '.container',
            data: {
                isShow: false,
                list: '',
                deleteids: [],
                page: 1,
                have_data: true
            },
            methods: {
                init: function() {
                    if (this.have_data) {
                        this.getdata();
                    } else {
                        $app.toast("没有更多数据了！");
                    }
                },
                //单选
                listImgActive: function(et) {
                    if (!this.isShow) {
                        //--去商品详情页
                        var goods_id = et.currentTarget.dataset.goodsid;
                        var is_member = et.currentTarget.dataset.ismember;
                        $app.openWin('buyGoods', {
                            goodsId: goods_id,
                            isSeller: +is_member
                        });
                        return;
                    }
                    var that = this;
                    var el = et.currentTarget;
                    var stid = el.dataset.stid;
                    var deleteids = that.deleteids;
                    var li = this.$refs.myFootprintList.querySelectorAll("li");
                    var all = this.$refs.footprintCheckAll;
                    if (el.classList.contains("active")) {
                        el.classList.remove("active");
                        all.checked = false;
                        var index = deleteids.indexOf(stid);
                        deleteids.splice(index, 1);
                    } else {
                        el.classList.add("active");
                        deleteids.push(stid);
                        for (var i = 0; i < li.length; i++) {
                            if (!li[i].classList.contains("active")) {
                                all.checked = false;
                                break;
                            }
                            if (li[i].classList.contains("active") && i == li.length - 1) {
                                all.checked = true;
                            }
                        }
                    }
                },
                //--取消编辑
                cancelEdit: function() {
                    var li = this.$refs.myFootprintList.querySelectorAll("li");
                    var deleteids = this.deleteids;
                    deleteids.splice(0, deleteids.length);
                    for (var i = 0; i < li.length; i++) {
                        li[i].classList.remove("active");
                    }
                    this.isShow = false;
                    document.querySelector("#myFootprintEdit").innerHTML = '编辑';
                },
                //--全选
                footprintCheckAll: function(et) {
                    var li = this.$refs.myFootprintList.querySelectorAll("li");
                    var that = this;
                    var deleteids = that.deleteids;
                    deleteids.splice(0, deleteids.length);
                    if (et.target.checked) {
                        for (var i = 0; i < li.length; i++) {
                            li[i].classList.add("active");
                            deleteids.push(li[i].dataset.stid);
                        }
                    } else {
                        for (var i = 0; i < li.length; i++) {
                            li[i].classList.remove("active");
                        }
                    }
                },
                //获取数据
                getdata: function() {
                    var that = this;
                    var unionId = $api.getStorage("shop_unionid");
                    $app.ajax(service['getStepList'], {
                        data: {
                            values: {
                                unionid: unionId,
                                page: that.page
                            }
                        }
                    }, function(res) {
                        console.log("get_data：" + JSON.stringify(res));
                        if (res.code == 0) {
                            if (that.page == 1) {
                                that.list = res.data;
                            } else {
                                for (var i = 0; i < res.data.length; i++) {
                                    that.list.push(res.data[i]);
                                }
                            }
                            that.have_data = res.data.length <= 0 ? false : true;
                            that.$refs.myFootprintNull.style.display = that.list.length <= 0 ? 'block' : 'none';
                            if (that.list.length <= 0) {
                                that.isShow = false;
                                document.querySelector("#myFootprintEdit").innerHTML = '编辑';
                            }
                        }
                    });
                },
                //上拉到底加载更多
                downflash: function() {
                    var that = this;
                    api.addEventListener({
                        name: 'scrolltobottom',
                        extra: {
                            threshold: 0 //设置距离底部多少距离时触发，默认值为0，数字类型
                        }
                    }, function(ret, err) {
                        // alert('已滚动到底部');
                        that.page++;
                        that.init();
                    });
                },
                //删除足迹记录
                canclestep: function() {
                    var deleteids = this.deleteids;
                    var unionId = $api.getStorage("shop_unionid");
                    var data = this.list;
                    var that = this;
                    if (deleteids.length == 0) {
                        api.toast({
                            msg: "请勾选要删除的记录",
                            duration: 2000,
                            location: 'middle'
                        });
                    } else {
                        var stepids = deleteids.join(",");
                        $app.ajax(service['delUserStep'], {
                            data: {
                                values: {
                                    unionid: unionId,
                                    step_id: stepids
                                }
                            }
                        }, function(res) {
                            console.log("del_data：" + JSON.stringify(res));
                            if (res.code == 0) {
                                that.$refs.footprintCheckAll.checked = false;
                                that.list = [];
                                that.page = 1;
                                that.have_data = true;
                                that.init();
                            }
                        });
                    }
                }
            },
            mounted: function() {
                this.downflash(); //--加载更多
                var self = this;
                document.querySelector("#myFootprintEdit").addEventListener("click", function() {
                    if (self.list.length <= 0) {
                        self.isShow = false;
                        this.innerHTML = '编辑';
                        return;
                    }
                    if (self.isShow) {
                        self.isShow = false;
                        this.innerHTML = '编辑';
                    } else {
                        self.isShow = true;
                        this.innerHTML = '完成';
                    }
                });
            },
            created: function() {
                this.init();
            }
        };
        // var shopVue = new Vue(vm);
        var even = function() {

        };
        var newVue = new Vue(vm);
        even();

    })
}
